package com.tpo.jnotes.client.lib.component.popup;

import static com.tpo.jnotes.base.colors.schema.BCSSManager.getCurrentCSS;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPopupMenu;

import com.tpo.jnotes.base.evernote.BEvernoteUtil;
import com.tpo.jnotes.base.resource.BResConstants;
import com.tpo.jnotes.base.resource.BResource;
import com.tpo.jnotes.client.layer.view.dialogs.NIFrame;
import com.tpo.jnotes.client.lib.component.dialog.NAboutDialog;

public class NPopup extends JPopupMenu
{
    private final NIFrame noteFrame;

    public NPopup( NIFrame aNoteFrameImpl )
    {
        setBackground( getCurrentCSS().getPopupBackground() );
        setForeground( getCurrentCSS().getPopupForeground() );
        add( getEvernoteMenuItem() );
        add( getAboutMenuItem() );
        this.noteFrame = aNoteFrameImpl;
    }

    private NPopupItem getEvernoteMenuItem()
    {
        NPopupItem everNoteMenuItem =
            new NPopupItem( "Send to Evernote", BResource.getIcon( BResConstants.EVERNOTE_IMG ) );
        everNoteMenuItem.setOpaque( false );
        everNoteMenuItem.addActionListener( new ActionListener()
        {

            @Override
            public void actionPerformed( ActionEvent e )
            {
                BEvernoteUtil.createNote( noteFrame.getTitle(), noteFrame.getText() );
            }
        } );
        return everNoteMenuItem;
    }

    private NPopupItem getAboutMenuItem()
    {
        NPopupItem aboutMenuItem = new NPopupItem( "About...", null );
        aboutMenuItem.setOpaque( false );
        aboutMenuItem.addActionListener( new ActionListener()
        {

            @Override
            public void actionPerformed( ActionEvent e )
            {
                NAboutDialog aboutD = new NAboutDialog();
                aboutD.pack();
                aboutD.setVisible( true );
            }
        } );
        return aboutMenuItem;
    }

}
